﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace System.Peppers.Win32
{
    [StructLayout(LayoutKind.Sequential)]
    internal class RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;

        public RECT()
        { }
        public RECT(int left, int top, int right, int bottom)
        {
            this.left = left;
            this.top = top;
            this.right = right;
            this.bottom = bottom;
        }

        public static RECT FromXYWH(int x, int y, int width, int height)
        {
            return new RECT(x, y, x + width, y + height);
        }
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    internal class MONITORINFOEX
    {
        internal int cbSize = Marshal.SizeOf(typeof(MONITORINFOEX));
        internal RECT rcMonitor = new RECT();
        internal RECT rcWork = new RECT();
        internal int dwFlags = 0;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)]
        internal char[] szDevice = new char[0x20];
    }

    [StructLayout(LayoutKind.Sequential)]
    internal class DEVMODE
    {
        public const int CCHDEVICENAME = 32;
        public const int CCHFORMNAME = 32;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
        public string dmDeviceName;
        public short dmSpecVersion;
        public short dmDriverVersion;
        public short dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
        public short dmDriverExtra;
        public int dmFields;

        public short dmOrientation;
        public short dmPaperSize;
        public short dmPaperLength;
        public short dmPaperWidth;

        public short dmScale;
        public short dmCopies;
        public short dmDefaultSource;
        public short dmPrintQuality;
        public short dmColor;
        public short dmDuplex;
        public short dmYResolution;
        public short dmTTOption;
        public short dmCollate;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
        public string dmFormName;
        public short dmLogPixels;
        public int dmBitsPerPel;    // Declared wrong in the full framework
        public int dmPelsWidth;
        public int dmPelsHeight;
        public int dmDisplayFlags;
        public int dmDisplayFrequency;

        public int dmICMMethod;
        public int dmICMIntent;
        public int dmMediaType;
        public int dmDitherType;
        public int dmReserved1;
        public int dmReserved2;
        public int dmPanningWidth;
        public int dmPanningHeight;

        public int dmPositionX; // Using a PointL Struct does not work 
        public int dmPositionY;
    }

    [StructLayout(LayoutKind.Sequential)]
    internal sealed class NETRESOURCE
    {
        public RESOURCESCOPE dwScope = 0;
        public RESOURCETYPE dwType = 0;
        public RESOURCEDISPLAYTYPE dwDisplayType = 0;
        public RESOURCEUSAGE dwUsage = 0;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpLocalName = null;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpRemoteName = null;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpComment = null;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpProvider = null;
    }
}
